package com.wgchao.identityrightsmanagement.domain.organization.model;

import com.wgchao.identityrightsmanagement.infrastructure.exception.ObjectDisabledException;
import com.wgchao.identityrightsmanagement.infrastructure.exception.ObjectNotMatchException;
import org.springframework.stereotype.Component;

/**
 * @ClassName: AssignOfficeToDepartmentService
 * @author: wgchao
 * @createTime: 2020/6/8 8:50 AM
 * @Description: 向部门分配角色
 */
@Component
public class AssignOfficeToDepartmentService {

    //向部门分配角色
    public DepartmentOffice assignOfficeToDepartment(String identify, Department department, Office office){
        department.normalException();
        office.normalException();
        if(!department.getAgencyCode().equals(office.getAgencyCode())){
            throw new ObjectNotMatchException("部门与职位不属于同一机构");
        }
        DepartmentOffice departmentOffice = new DepartmentOffice(identify, department.getCode(), office.getCode());

        return departmentOffice;
    }

}
